<!-- 列表 -->
<template>
	<div class="td-page">
		<co-table ref="tableRef" v-bind="tableConfig">
			<div slot="toolbar">
				<el-button class="el-button--danger c-l-w-100-button" @click.stop="add">新建</el-button>
			</div>
			<el-table-column label="操作" width="120" fixed="right">
				<template slot-scope="scope">
					<el-button type="text" @click="edit(scope.row)">编辑</el-button
					><el-button type="text" @click="modifyStoreContractStatus(scope.row)">审核</el-button>
				</template>
			</el-table-column>
		</co-table>
	</div>
</template>

<script>
import api from '@/api/api'
import util from '@/assets/js/co-util'
import { tableConfig } from './pn-list.data.js'
export default {
	name: 'pn-list',
	data() {
		return {
			tableConfig: Object.assign(
				{
					apiName: 'AdminStoreContractService.listStoreContract',
				},
				tableConfig.call(this)
			),
		}
	},
	activated() {
		this.$refs.tableRef.search()
	},
	methods: {
		add(row) {
			// 编辑
			this.$router.push({ name: 'modify', params: { id: 0, type: 'add' } })
		},
		edit(row) {
			// 编辑
			this.$router.push({ name: 'modify', params: { id: row.id, type: 'edit' } })
		},
		modifyStoreContractStatus(row) {
			util.confirm('确认审核该记录', this.doModifyStoreContractStatus, row)
		},
		doModifyStoreContractStatus(row) {
			// 这里的参数需要开发者修改
			api.AdminStoreContractService.modifyStoreContractStatus({
				data: { id: row.id },
			}).then((res) => {
				this.$refs.tableRef.search()
				util.message({
					type: 'success',
					message: '操作成功',
				})
			})
		},
	},
}
</script>
